package com.punch.course.controller;

import com.punch.common.model.Result;
import com.punch.common.page.PageInfo;
import com.punch.common.vo.course.SignInClassVO;
import com.punch.common.vo.course.SignInStudentVO;
import com.punch.course.service.SignInService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 签到控制层
 */
@RestController
@Api(value = "SignInController", tags = "签到Controller")
public class SignInController {

    @Resource
    private SignInService signInService;

    /**
     * 查找当前登录教师的需要上课的课程列表
     *
     * @return PageInfo
     */
    @GetMapping(value = "/sign-in/class-course", produces = "application/json; charset=utf-8")
    @ApiOperation(value = "查找当前登录教师的需要上课的课程列表", notes = "查找当前登录教师的需要上课的课程列表", produces = "application/json")
    public Result<List<SignInClassVO>> listClassCourse() {
        return Result.succeed(signInService.listClassCourse());
    }

    /**
     * 获取课程下学生列表
     *
     * @param classId 学生id
     * @return List<SignInStudentVO>
     */
    @GetMapping(value = "/sign-in/class-course-student/{classId}", produces = "application/json; charset=utf-8")
    @ApiOperation(value = "获取课程下学生列表", notes = "获取课程下学生列表", produces = "application/json")
    public Result<PageInfo<SignInStudentVO>> listCourseStudent(@PathVariable Long classId,
                                                               @RequestParam(name = "studentName", required = false) String studentName,
                                                               @RequestParam(name = "schoolId", defaultValue = "0") Long schoolId,
                                                               @RequestParam(value = "currPage", defaultValue = "1") Integer currPage,
                                                               @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        return Result.succeed(signInService.listCourseStudent(classId, studentName, schoolId, currPage, pageSize));
    }

    /**
     * 修改学生课表签到状态
     *
     * @param courseScheduleId 签到id
     * @param signInStatus     签到状态 0-还原初始状态(清空) 1-已到 2-请假
     * @return long
     */
    @PutMapping(value = "/sign-in/class-course-student/status/{courseScheduleId}/{signInStatus}", produces = "application/json; charset=utf-8")
    @ApiOperation(value = "修改学生课表签到状态", notes = "修改学生课表签到状态", produces = "application/json")
    public Result<Long> changeSignInStatus(@PathVariable Long courseScheduleId, @PathVariable Integer signInStatus) {
        return Result.succeed(signInService.changeSignInStatus(courseScheduleId, signInStatus));
    }


    /**
     * 统计签到人数
     *
     * @param classId 班级课程id
     * @return Integer
     */
    @GetMapping(value = "/sign-in/class-course-student-count/{classId}", produces = "application/json; charset=utf-8")
    @ApiOperation(value = "统计签到人数", notes = "统计签到人数", produces = "application/json")
    public Result<Integer> getSignInCount(@PathVariable Long classId) {
        return Result.succeed(signInService.getSignInCount(classId));
    }

}
